package com.ymttest.business.service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;

import com.xlobo.api.fund.parameter.CreateAccountInfoBean;
import com.xlobo.api.fund.parameter.InfoBean;
import com.xlobo.api.fund.service.CreateAccountInfoCall;
import com.xlobo.api.fund.service.InfoCall;
import com.ymttest.utils.TestDataManager;

public class XloboAccountCallService {

	/**
	 * 生成UserID
	 * 
	 * @param accountType
	 *            账号类型
	 * @return map
	 */
	@SuppressWarnings("rawtypes")
	public static Map<String, Comparable> getAccount(int accountType) {
		Map<String, Comparable> map = new HashMap<String, Comparable>();
		CreateAccountInfoBean caccountbean = new CreateAccountInfoBean();
		CreateAccountInfoCall caccountcall = new CreateAccountInfoCall();
		String uuid = TestDataManager.getRandomUUID().toString();
		caccountbean.setUserId(uuid);
		caccountbean.setAccountType(accountType);
		String uname = TestDataManager.getChineseName();
		caccountbean.setUserName(uname);
		String email = TestDataManager.getEmail();
		caccountbean.setEmail(email);
		caccountbean.setAction(0);
		caccountcall.setData(false,caccountbean);
		try {
			caccountcall.callService();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		map.put("UserId", uuid);
		map.put("Uname", uname);
		map.put("AccountType", accountType);

		return map;
	}

	/**
	 * 获取AccountId
	 */
	@SuppressWarnings("rawtypes")
	public static Map<String, Comparable> getAccountId() {
		Map<String, Comparable> map = new HashMap<String, Comparable>();
		String AccountId = null;
		try {
			InfoBean infobean = new InfoBean();
			InfoCall infocall = new InfoCall();
			Map map2 = XloboAccountCallService.getAccount(0);
			infobean.setUserId((String) map2.get("UserId"));
			infobean.setUserAccountType(0);
			infocall.setData(false,infobean);
			infocall.callService();
			AccountId = infocall.getAccountId();
			map.put("AccountId", AccountId);
			map.put("AccountType", 0);
			map.put("UserId", (String) map2.get("UserId"));
		} catch (Exception e) {
			e.printStackTrace();
		}

		return map;
	}
}
